home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 604 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.worldlinx.com!stupy
  2. From: stupy@freenet.durham.org (Steve Tupy)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Function template problem
  5. Date: 5 Jan 1996 06:24:28 GMT
  6. Organization: Durham Free-Net
  7. Message-ID: <4cig6s$ii5@news.worldlinx.com>
  8. References: <1996Jan1.121642.44508@ac.dal.ca>
  9. NNTP-Posting-Host: freenet.durham.org
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Adrian Ross Cook (cook@is.dal.ca) wrote:
  13. : Hi there. Is it legal to use a template function as a member function of 
  14. : a non-template class? If so, what is the proper syntax for doing this?
  15.  
  16. : Currently I have something like the following:
  17.  
  18. : class Blah{
  19. :    ...other functions...
  20. :    template <class Type>
  21. :    Type foo(int index, Type aVal);
  22. : };
  23.  
  24.     the template does not need to be here as this is the prototype. 
  25.  
  26. : and in my definitions file:
  27.  
  28. : template <class Type>
  29. : Type Blah::foo(int index, Type aVal)
  30. : {
  31. :  ...code...
  32. : }
  33.     This part looks ok. Not sure if this will work, though, what problem
  34. do you have with templating the whole class?
  35.  
  36. : Anyway, my compiler (Turbo C++ for Windows 3.1) won't accept this. It 
  37. : seems to be confusing my function template with a class template. 
  38. : However, none of the C++ books I have say that you can't use a template 
  39. : function as a class member function.
  40.  
  41.     Watch this, Turbo C is not well equipped to handle templates,
  42. certainly not as equipped as Borland flavored compilers.
  43.  
  44.  
  45. --
  46. Steve
  47.